package org.publish.service;

import org.publish.dto.EquationRequest;
import org.publish.dto.EquationResponse;
import org.publish.dto.NoValidSolutionException;
import org.springframework.stereotype.Service;

@Service
public class EquationService {
    public EquationResponse solve(EquationRequest request) {
        double a = request.getA();
        double b = request.getB();

        // 解方程逻辑
        double x = a - b;
        double y = 2 * b - a;

        if (x <= 0 || y <= 0) {
            throw new NoValidSolutionException("方程的解为负数或0，视为无实际意义解");
        }

        return new EquationResponse(x, y);
    }
}
